package com.code.jvm.reference.soft;

import java.lang.ref.SoftReference;

public class SoftClient {

    public static void main(String[] args) {
        SoftReference<byte[]> softReference = new SoftReference<>(new byte[1024 * 1024 * 10]);
        System.out.println(softReference.get());
        //触发垃圾回收
        System.gc();
        System.out.println(softReference.get());
        //最大堆内存是20M，所以创建了以下10M左右的数组导致JVM内存不足触发回收软引用对象
        byte[] bytes = new byte[1024 * 1024 * 10];
        //获取就是null
        System.out.println(softReference.get());
    }
}
